// pages/auth/auth.js
import {
    request
} from "../../request/request";
import {
    login
} from "../../request/login";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        swiperData: [],
        nihao: {
            "message": {
                "user_id": 23,
                "user_email_code": null,
                "is_active": null,
                "user_sex": "男",
                "user_qq": "",
                "user_tel": "",
                "user_xueli": "本科",
                "user_hobby": "",
                "user_introduce": null,
                "create_time": 1562221487,
                "update_time": 1562221487,
                "token": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
            }
        }
    },
    // 获取用户的信息
    async quan(e) {
        // try {
        const {
            encryptedData,
            rawData,
            iv,
            signature
        } = e.detail;
        // console.log( encryptedData,
        //     rawData,
        //     iv,
        //     signature);
        const {
            code
        } = await login()
        // console.log(code)
        const loginParams = {
            encryptedData,
            rawData,
            iv,
            signature,
            code
        }
        // 获取用户的token
        // let nihao = encryptedData+rawData+iv+signature+code
        let nihao = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
        var token = [nihao]
        // const {
        //     token
        // } = await request({
        //     url: "https://api-hmugo-web.itheima.net/api/public/v1/categories",
        //     data: loginParams,
        //     method: "post"
        // })
        wx.setStorageSync("token", token);
        wx.navigateBack({
            delta: 1,
          })
        // } catch (error) {
        //     console.log(error)
        // }
    },

    // quan(){
    //      request({
    //         url: "https://api-hmugo-web.itheima.net/api/public/v1/users/wxlogin",
    //     }).then((res) => {
    //         this.setData({
    //             swiperData: res.data.message
    //         })
    //     })
    // },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})